﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace Trade.Journal
{
    /// <summary>
    /// TradeOpportunitySelecter.xaml 的交互逻辑
    /// </summary>
    public partial class TradeOpportunitySelecter : UserControl
    {
        public TradeOpportunitySelecter()
        {
            InitializeComponent();
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DataContext is TradeOpportunitySelecterVM v)
            {
                if (v.SelectedSpecialType == SpecialType.Normal || v.SelectedSpecialType == SpecialType.Overweight || v.SelectedSpecialType == SpecialType.Balance)
                {
                    DockPanel.SetDock(sender as UIElement, Dock.Left);
                    (sender as Control).Width = ActualWidth / 2;
                }
                 else
                {
                    DockPanel.SetDock(sender as UIElement, Dock.Top);
                    (sender as Control).Width = 50;
                }
            }
        }
    }


    public class TradeOpportunitySelecterVM : BindableBase
    {
        private SpecialType? _SpecialType;


        public SpecialType? SelectedSpecialType
        {
            get { return _SpecialType; }
            set { SetProperty(ref _SpecialType, value, nameof(SelectedSpecialType), nameof(ShowSecond), nameof(ShowThird), nameof(CategoryTypes)); SelectedCategoryType = null; }
        }

        private CategoryType[]? _SelectedCategoryType;

        public CategoryType[]? SelectedCategoryType
        {
            get { return _SelectedCategoryType; }
            set { SetProperty(ref _SelectedCategoryType, value); }
        }


        public bool ShowSecond => SelectedSpecialType != null ;

        public bool ShowThird => SelectedSpecialType == SpecialType.Resonate;


        public SpecialType[] SpecialTypes { get; } = new SpecialType[] { Trade.Journal.SpecialType.Normal, Trade.Journal.SpecialType.Overweight, Trade.Journal.SpecialType.Resonate, SpecialType.Balance };

        private Dictionary<SpecialType, CategoryType[]> CategoryTypeDict { get; } = new Dictionary<SpecialType, CategoryType[]>
            {
                { Trade.Journal.SpecialType.Normal, new CategoryType[] { CategoryType.Rectangle, CategoryType.FlagShaped, CategoryType.Triangle, CategoryType.DoublePole, CategoryType.HeadShoulder } },
                { Trade.Journal.SpecialType.Overweight, new CategoryType[] { CategoryType.Rectangle, CategoryType.FlagShaped, CategoryType.Triangle, CategoryType.VShaped, CategoryType.Heteroideus } },
                { Trade.Journal.SpecialType.Resonate, new CategoryType[] { CategoryType.Rectangle, CategoryType.FlagShaped, CategoryType.Triangle, CategoryType.DoublePole, CategoryType.HeadShoulder, CategoryType.VShaped, CategoryType.Heteroideus } },
                {SpecialType.Balance, new CategoryType[]{ CategoryType.ExtreamPoint, CategoryType.Sideline} }
        };


        public CategoryType[] CategoryTypes => SelectedSpecialType.HasValue ? CategoryTypeDict[SelectedSpecialType.Value] : null;




    }

}
